/**
 *
 */
function passwordLevel(password) {
  var Modes = 0;
  for (i = 0; i < password.length; i++) {
    Modes |= CharMode(password.charCodeAt(i));
  }
  return bitTotal(Modes);
  //CharMode函数
  function CharMode(iN) {
    if (iN >= 48 && iN <= 57) //数字
      return 1;
    if (iN >= 65 && iN <= 90) //大写字母
      return 2;
    if ((iN >= 97 && iN <= 122) || (iN >= 65 && iN <= 90))
      //大小写
      return 4;
    else
      return 8; //特殊字符
  }
  //bitTotal函数
  function bitTotal(num) {
    modes = 0;
    for (i = 0; i < 4; i++) {
      if (num & 1) modes++;
      num >>>= 1;
    }
    return modes;
  }
}

function validatephone(isExit) {
  var numbers = /^1\d{10}$/;
  var phone = $.trim($("#phone").val());
  var message = "";
  if (phone.length != 11 || !numbers.test(phone)) {
    message = "手机号码格式不正确";
  } else if (isExit) {
    var param = {};
    param.checksource = "mobile";
    param.mobile = phone;
    param = JSON.stringify(param);
    $.post(serverPath + "/authlogic/check/exist", param, function(data) {
      if (data.code != "00000") {
        message = data.desc;
      }
    });
  }
  if (message != "") {
    layer.msg(message);
    $("#phone").focus();
  }
  return message == "";
}

function validatekpass(islevel) {
  var pass = $.trim($("#password").val());
  var message = "";
  if (pass.length < 6) {
    message = "密码格式不正确";
  } else if (islevel && passwordLevel(pass) == 1) {
    message = "密码过于简单";
  }
  if (message != "") {
    layer.msg(message);
    $("#password").focus();
  }
  return message == "";
}

function validateicode() {
  var icode = $.trim($("#icode").val());
  var message = "";
  if (icode.length != 6) {
    message = "验证码格式不正确";
  }
  if (message != "") {
    layer.msg(message);
    $("#icode").focus();
  }
  return message == "";
}
$(function() {
  $('#codeimg').click(
    function() {
      $(this).attr(
        'src',
        serverPath + '/captcha.code?' +
        Math.floor(Math.random() * 100));
    });
});